// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';


// 申明请求对象
const calShiftRequest = {
    // calPlan请求的基本url
    BASE_URL : confing.CAL_URL + "/calShift",

    //编辑按钮相关事件
    //1.行编辑按钮的弹窗 根据id编辑
    edit(calShift,callback){
        if(calShift != undefined && calShift.shiftId != undefined){
            request.put(this.BASE_URL + "/update",calShift,callback)
        }
    },
    //2.行编辑按钮 需要根据id查询角色信息的api
    get(shiftId,callback){
        // 如果有teamId就准备url
        if(shiftId){
            // 准备url
            let url = this.BASE_URL + "/get?shiftId=" + shiftId;
            request.get(url,callback);//调用get方法
        }
        // 如果没有roleId,就不做任何处理
    },

    //批量删除班组计划
    deletes(shiftIds,callback){
        // 拼接URL
        let url = this.BASE_URL + "/deletes?t=1";
        if(shiftIds != undefined){
            shiftIds.forEach(shiftId => {
                url += "&shiftId=" + shiftId;
            });
            request.delete( url,callback);
        }
    },

    //行编辑按钮-删除按钮事件
    delete(shiftId,callback){
        request.delete(this.BASE_URL + "/" + shiftId,callback);
    },

    //添加班次
    save(calShift,callback){
        if(calShift){
            request.post(this.BASE_URL + "/save",calShift,callback);
        }
    },
    
    // 班次列表展示 分页
    list(page = 1,limit = 10,calShift,callbcak){
        // url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit;
        if(calShift){
            if(calShift.shiftId){
                url += "&shiftId=" + calShift.shiftId;
            }
            if(calShift.planId){
                url += "&planId=" + calShift.planId;
            }
        }
        // 发送请求
        request.get(url,callbcak);
    }
}


// 将calShiftRequest暴漏出去
export default calShiftRequest;